//
//  RSDBRelation.h
//  Chord Viewer
//
//  Created by Johnnie Walker on 05/09/2008.
//  Copyright 2008 Random Sequence. All rights reserved.
//

#import <UIKit/UIKit.h>

typedef NSUInteger  RSDBRecordRelationType;
enum _RSDBRecordRelationType {
    RSDBRecordRelationTypeBelongsToOne,
    RSDBRecordRelationTypeHasMany,
};

#define RSDBRelationLocalKey			@"RSDBRelationLocalKey"
#define RSDBRelationForeignKey			@"RSDBRelationForeignKey"
#define RSDBRelationLocalTableKey		@"RSDBRelationLocalTableKey"
#define RSDBRelationForeignTableKey		@"RSDBRelationForeignTableKey"
#define RSDBRelationRefTableKey			@"RSDBRelationRefTableKey"
#define RSDBRelationOwningTableKey		@"RSDBRelationOwningTableKey"	

@class RSDBRecord;
@class RSDBTable;

@interface RSDBRelation : NSObject {

	NSUInteger type;
	
	RSDBTable *localTable;
	RSDBTable *foreignTable;
	RSDBTable *owningTable;	
	RSDBTable *refTable;	
	
	NSString *localKey;
	NSString *foreignKey;
}

@property (nonatomic, retain) RSDBTable *localTable;
@property (nonatomic, retain) RSDBTable *foreignTable;
@property (nonatomic, retain) RSDBTable *owningTable;
@property (nonatomic, retain) RSDBTable *refTable;
@property (nonatomic, retain) NSString *localKey;
@property (nonatomic, retain) NSString *foreignKey;
@property (nonatomic) NSUInteger type;

+ (id)relationWithType:(RSDBRecordRelationType)type options:(NSDictionary *)options;
- (id)initWithType:(RSDBRecordRelationType)type options:(NSDictionary *)options;

- (RSDBRecord *)getOwnerForRecord:(RSDBRecord *)record;
- (NSArray *)getRecordsOwnedBy:(RSDBRecord *)record;
@end
